<template>
    <el-container>
        <el-header v-if="!isDisabled">
            <el-button
                    @click="item_moveUp"
                    v-if="itemIndex !== 0"
                    type="primary"
                    icon="el-icon-upload2"
                    circle></el-button>
            <el-button
                    @click="item_moveDown"
                    v-if="itemIndex !== answerCount-1"
                    type="success"
                    icon="el-icon-download"
                    circle></el-button>
            <el-button
                    @click="item_delQuestion"
                    type="danger"
                    icon="el-icon-delete"
                    circle></el-button>
        </el-header>
        <el-main>
            <svg-icon v-if="item_que.required === 1" icon-class="必填" style="width:32px;height:32px;float: left;margin-right:5px"></svg-icon>
            <p style="font-size: 18px;color: #3b91b6">文本题</p>
            <el-form
                    ref="dataForm"
                    :model="item_que"
                    label-position="center"
                    label-width="150px"
                    :class="[isDisabled?'normal':'no_normal']"
            >
                <el-row :gutter="20">
                    <el-col :span="6">
                        <el-form-item
                                label="排序："
                                prop="viewSort"
                        >
                            <el-input  v-model="item_que.viewSort"  type="text" placeholder="问题序号,如1/I/一/①..." class="inputBox" :disabled="isDisabled"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="18">
                        <el-form-item
                                label="问题描述："
                                prop="title"
                        >
                            <el-input  v-model="item_que.title"  type="text" placeholder="问题描述..." class="inputBox" :disabled="isDisabled"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-form-item
                        label="问题备注/副标题："
                        prop="description"
                >
                    <el-input  v-model="item_que.description"  type="text" placeholder="问题备注..." class="inputBox" :disabled="isDisabled"></el-input>
                </el-form-item>

                <el-form-item
                        label="用户回答文本："
                        prop="description"
                        v-if="item_que.isArea === 0"
                >
                    <el-input    type="text" placeholder="用户回答用输入框..." class="inputBox" :disabled="true"></el-input>
                </el-form-item>

                <el-form-item
                        label="用户回答文本："
                        prop="description"
                        v-if="item_que.isArea === 1"
                >
                    <el-input    type="textarea" placeholder="用户回答用文本域..." class="inputBox" :disabled="true"></el-input>
                </el-form-item>

            </el-form>
            <el-collapse v-if="!isDisabled">
                <el-divider><i class="el-icon-s-tools"></i></el-divider>
                <el-collapse-item title="更多设置..." name="foot" >
                    <el-form
                            ref="dataForm"
                            :model="item_que"
                            label-position="center"
                            label-width="120px"
                    >
                        <el-row :gutter="10">
                            <el-col :span="8">
                                <el-form-item
                                        label="是否必填："
                                >
                                    <el-radio v-model="item_que.required" :label=0>否</el-radio>
                                    <el-radio v-model="item_que.required" :label=1>是</el-radio>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item
                                        label="必填校验提示："
                                >
                                    <el-input v-if="item_que.required===1"
                                              v-model="item_que.errorMsg"
                                              type="text" placeholder="此题必选!" class="inputBox"
                                    ></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="8">
                                <el-form-item
                                        label="是否是文本域："
                                >
                                    <el-radio v-model="item_que.isArea" :label=0>否</el-radio>
                                    <el-radio v-model="item_que.isArea" :label=1>是</el-radio>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row :gutter="10">
                            <el-col :span="12">
                                <el-form-item
                                        label="是否常用："
                                >
                                    <el-radio v-model="item_que.isCommon" :label=0>不常用</el-radio>
                                    <el-radio v-model="item_que.isCommon" :label=1>常用</el-radio>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item
                                        label="状态："
                                >
                                    <el-radio v-model="item_que.status" :label=0>可用</el-radio>
                                    <el-radio v-model="item_que.status" :label=1>禁用</el-radio>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                </el-collapse-item>
            </el-collapse>
        </el-main>
    </el-container>
</template>

<script>
    export default {
        name: "item_textarea",
        data() {
            return {
                item_que:Object.assign({}, this.itemData)
            }
        },
        watch: {
            isDisabled: function(newVal){
                this.gotUpData()
            },
        },
        props: {
            itemData:Object,
            isDisabled:Boolean,
            answerCount:Number,
            itemIndex:Number,
            moveUp:Function,
            moveDown:Function,
            delQuestion:Function,
            itemUpDataItem:Function,
        },
        methods: {
            item_delQuestion(){
                this.delQuestion(this.itemIndex)
            },
            item_moveUp(){
                this.moveUp(this.itemIndex)
            },
            item_moveDown(){
                this.moveDown(this.itemIndex)
            },
            gotUpData(){
                this.itemUpDataItem(this.itemIndex,this.item_que);
            }
        }

    }
</script>

<style scoped>
    .normal{
        width: 90%; margin-left:50px;background: #e3e3e3;border:1px solid #000;
    }
    .no_normal{
        width: 90%; margin-left:50px;background: #fff;border:1px solid #000;
    }
</style>
